import LinkedList, { LinkNode } from "./LinkedList";

const {ccclass, property} = cc._decorator;

@ccclass
export class Handler<T> {
    private callback: (this: T, ...args: any[]) => void;
    private context: T;
    public args: any[]; // 保存构造时传入的参数

    constructor(callback: (this: T, ...args: any[]) => void, context: T, ...args: any[]) {
        this.callback = callback;
        this.context = context;
        this.args = args; // 保存传入的参数
    }

    // 使用保存的参数执行回调方法
    public invoke(...args: any[]) {
        if (args.length > 0) {
            this.args = args;
        }
        this.callback.apply(this.context, this.args);
    }
}
export class ProgressHandler {
    enter: any = null
    stay:  any = null
    exit: any = null
    linkList = new LinkedList();
    constructor(enter:any,stay:any,exit:any) {
        this.enter = enter;
        this.stay = stay;
        this.exit = exit;
        this.linkList.append(enter);
        this.linkList.append(stay);
        this.linkList.append(exit);
        //此结构不需要循环链表，直接解除
        this.linkList.head.prev.next = null;
        this.linkList.print();
    }

    

    
}

export default class ProgressMgr<T> {
    
    progress: LinkedList<T> = new LinkedList();
    constructor(progress: Array<LinkNode<T>>) {
        
        progress.forEach((item) => {
            //let progressUnit = new ProgressHandler<T>(item[0], item[1], item[2]);
            this.progress.append(item);
        });
        this.progress.initCurrent()
        console.log(this.progress)
    }
    
    startProgress() {
        this.progress.head.data.invoke();
        
    }

    next(){
        this.progress.current = this.progress.current.next;
        this.progress.current.data.invoke();
        console.log(this.progress.current,"next之后current")
    }

    
}
